<template>
  <div>
    <!-- 切换代理商 -->
    <el-dialog
      top="5vh"
      width="60%"
      title="请选择需要切换的代理商"
      :visible.sync="visible"
      :close-on-click-modal="false"
      class="cahnge_school"
      :append-to-body="true"
    >
      <el-form :model="form">
        <el-form-item>
          <el-col :span="15">
            <el-input v-model="form.schoolname" autocomplete="off" size="small">
              <el-button slot="append" icon="el-icon-search" @click="searchschool()"></el-button>
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item>
          <span class="dls_name">代理商列表</span>
        </el-form-item>
        <el-form-item>
          <div class="school_div">
            <el-row>
              <el-col :span="6" v-for="(item,index) in allschoollist" :key="index">
                <icon-svg name="school" class="site-sidebar__menu-icon"></icon-svg>
                <a
                  href="javascript:void(0);"
                  @click="getuintId(item.unitGuid,item.unitName,item.unitType)"
                >{{item.unitName}}</a>
              </el-col>
            </el-row>
          </div>
        </el-form-item>
      </el-form>
      <div class="page" v-show="recordCount>20?true:false">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChangepage"
          :current-page="currentPage"
          :page-sizes="[ 10, 20, 30, 40]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="recordCount"
        ></el-pagination>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 切换用户
export default {
  data() {
    return {
      visible: false,
      updatePassowrdVisible: false,
      switchSchoolVisible: false,
      dialogFormVisible: false,
      userGuid: "",
      form: {
        schoolname: "",
      },
      allschoollist: [],
      pageNum: 1,
      pageSize: 10,
      recordCount: 0,
      currentPage: 1,
      searchInfo: {},
    };
  },
  created() {
    this.username = sessionStorage.getItem("username");
    this.userType = sessionStorage.getItem("userType");
    this.userGuid = sessionStorage.getItem("administrator");
    this.unitType = sessionStorage.getItem("unitType");
  },
  mounted() {},
  methods: {
    init() {
      this.visible = true;
      this.allschool();
    },
    // 获取代理商
    allschool() {
      this.searchInfo.agentGuid = this.userGuid;
      this.searchInfo.unitType = 50; // 代理商单位
      this.searchInfo.unitGuid = this.$store.state.user.changeschoolid;
      if (this.form.schoolname != null && this.form.schoolname !== "") {
        this.searchInfo.unitName = this.form.schoolname;
      }
      this.$http({
        url: this.$http.adornUrl("/manager/unit-info-page"),
        method: "post",
        data: this.$http.adornData({
          messageContent: {
            pageNum: this.pageNum,
            pageSize: this.pageSize,
            searchInfo: this.searchInfo,
          },
          messageType: this.messageType,
        }),
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          this.allschoollist = data.messageContent.data;
          this.recordCount = data.messageContent.recordCount;
          this.currentPage = data.messageContent.pageNum;
          this.searchInfo = {};
        } else {
          this.$message.error(data.errorMessage);
        }
      });
    },
    //分类页
    handleSizeChange(val) {
      this.pageSize = val;
      this.searchInfo.userGuid = this.userGuid;
      this.allschool();
    },
    handleCurrentChangepage(val) {
      this.searchInfo.userGuid = this.userGuid;
      this.pageNum = val;
      this.allschool();
    },
    searchschool() {
      if (this.form.schoolname != null && this.form.schoolname !== "") {
        this.searchInfo.unitName = this.form.schoolname;
      }
      this.searchInfo.userGuid = this.userGuid;
      this.allschool();
    },
    getuintId(id, name, type) {
      sessionStorage.setItem("unitType", type);
      this.$store.commit("user/updateSelectedUnigInfo", {
        unitType: type,
        unitGuid: id,
        unitName: name,
      });
      this.mainTabs = [];
      this.menuActiveName = "";
      this.$router.options.isAddDynamicMenuRoutes = false;
      this.$router.push({ name: "home", query: { type: type } });
      setTimeout(() => {
        this.$store.commit(
          "common/updateMenuList",
          JSON.parse(sessionStorage.getItem("menuList") || "[]")
        );
        this.$store.commit(
          "common/updateDynamicMenuRoutes",
          JSON.parse(sessionStorage.getItem("dynamicMenuRoutes") || "[]")
        );
        this.$router.push({ path: "/" });
      }, 100);

      this.visible = false;
    },

    resetstore() {
      this.$store.commit("resetStore", val);
    },
  },
};
</script>

<style lang="scss" scoped>
.el-badge {
  /deep/.el-badge__content {
    background-color: #17b3a3;
  }
}
.el-menu--horizontal > .el-menu-item {
  color: #303133;
}
.school_size {
  font-size: 18px;
  font-weight: bold;
  display: flex;
  align-items: center;
}
.cahnge_school {
  /deep/.el-dialog__body {
    padding: 10px 20px;
    // overflow-y:scroll;
    .el-form-item {
      margin-bottom: 0px;
      // padding-bottom: 10px;
      border-top: 1px solid #ccc;
      .dls_name {
        font-size: 20px;
      }
    }
    .el-form-item:nth-child(1) {
      border-top: 0px solid #ccc;
      margin-bottom: 20px;
    }
    .el-form-item:nth-child(3) {
      padding-top: 30px;
      padding-bottom: 20px;
    }
  }
}
.page {
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>